<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var wiggleMaxLength = function (nums) {
            let flag = false
            let diff = []
            for (let i = 1; i < nums.length; i++) {
                if (nums[i] != nums[i - 1]) {
                    flag = true
                }
                diff.push(nums[i]-nums[i-1])
            }
            if (!flag || nums.length==1) {
                return 1;
            }
            for (let i = 1; i < diff.length; i++) {
                if (diff[i-1]==0){
                    diff.splice(i-1,1)
                    i--
                }
                if (diff[i-1]*diff[i]>=0){
                    diff.splice(i,1)
                    i--
                }
            }
            return diff.length+1
        };
        console.log(wiggleMaxLength([3,3,3,2,5]))
    </script>
</body>

</html>